Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
flatbuffers
Advanced tools
FlatBuffers is an efficient cross-platform serialization library for C++, C#, C, Go, Java, JavaScript, TypeScript, PHP, and Python. It allows you to create and access serialized data without parsing/unpacking it, making it ideal for performance-critical applications.
Creating a FlatBuffer
This code demonstrates how to create a FlatBuffer with a string and a vector of strings. The buffer is then finished and converted to a Uint8Array.
const flatbuffers = require('flatbuffers');
const builder = new flatbuffers.Builder(1024);
// Create a string
const str = builder.createString('Hello, FlatBuffers!');
// Create a vector of strings
const strings = builder.createVectorOfStrings(['foo', 'bar', 'baz']);
// Finish the buffer
builder.finish(strings);
// Get the buffer
const buf = builder.asUint8Array();
console.log(buf);
Reading a FlatBuffer
This code demonstrates how to read a FlatBuffer. It assumes that the buffer contains data for a 'Monster' object, and it accesses the 'name' and 'hp' fields of the object.
const flatbuffers = require('flatbuffers');
const MyGame = require('./mygame_generated'); // Generated code
// Assume buf is a Uint8Array containing the FlatBuffer data
const buf = new Uint8Array([/* FlatBuffer data */]);
// Get the root object
const bb = new flatbuffers.ByteBuffer(buf);
const root = MyGame.Example.Monster.getRootAsMonster(bb);
// Access data
console.log(root.name());
console.log(root.hp());
Protobuf.js is a pure JavaScript implementation of Protocol Buffers, a language-neutral, platform-neutral, extensible mechanism for serializing structured data. Compared to FlatBuffers, Protobuf.js requires a parsing step to access data, which can be less efficient in performance-critical applications.
MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON but it's faster and smaller. Compared to FlatBuffers, MessagePack is simpler but may not offer the same level of performance for complex data structures.
Avro is a data serialization system that provides rich data structures and a compact, fast, binary data format. The 'avsc' package is a pure JavaScript implementation of Avro. Compared to FlatBuffers, Avro is more focused on schema evolution and data interchange, while FlatBuffers is optimized for performance.
FlatBuffers is a cross platform serialization library architected for maximum memory efficiency. It allows you to directly access serialized data without parsing/unpacking it first, while still having great forwards/backwards compatibility.
Go to our landing page to browse our documentation.
and more in progress...
flatbuffers
tag for any questions regarding FlatBuffers.To contribute to this project, see CONTRIBUTING.
Flatbuffers is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.
FAQs
Memory Efficient Serialization Library
The npm package flatbuffers receives a total of 260,316 weekly downloads. As such, flatbuffers popularity was classified as popular.
We found that flatbuffers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.